package com.ems.service.impl.supers.questions;

import com.ems.dao.supers.questions.JudgmentDao;
import com.ems.dao.supers.questions.answer.JudgmentAnswerDao;
import com.ems.pojo.data.RequestData;
import com.ems.pojo.questions.Judgment;
import com.ems.pojo.questions.Subject;
import com.ems.pojo.questions.answer.JudgmentAnswer;
import com.ems.service.supers.questions.JudgmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: 伟伟
 * @Date: 2019/10/19
 * @Description: 判断题
 * @Version: 1.0
 */
@Service("judgmentService")
public class JudgmentServiceImpl implements JudgmentService {

    @Autowired
    private JudgmentDao judgmentDao;

    @Autowired
    private JudgmentAnswerDao judgmentAnswerDao;

    private JudgmentAnswer judgmentAnswer;

    /**
     * 添加判断题
     * @param judgmentList
     */
    @Override
    public void addJudgment(List<Judgment> judgmentList) {
        Judgment judgment = null;
        for(int i = 0;i < judgmentList.size();i ++){
            judgment = judgmentList.get(i);
            judgmentDao.addJudgment(judgment);
            judgmentAnswer = judgment.getJudgmentAnswer();
            judgmentAnswer.setJ_id(judgment.getJ_id());
            judgmentAnswerDao.addJudgmentAnswer(judgmentAnswer);
        }

    }

    /**
     * 删除判断题
     * @param judgmentList
     */
    @Override
    public void deleteJudgment(List<Judgment> judgmentList) {
        for(int i = 0;i < judgmentList.size();i ++){
            judgmentAnswerDao.deleteJudgmentAnswer(judgmentList.get(i).getJudgmentAnswer());
            judgmentDao.deleteJudgment(judgmentList.get(i));
        }
    }

    /**
     * 修改指定的判断题
     * @param judgment
     */
    @Override
    public void updateJudgment(Judgment judgment) {
       judgmentDao.updateJudgment(judgment);
       judgmentAnswerDao.updateJudgmentAnswer(judgment.getJudgmentAnswer());
    }

    /**
     * 按照条件查询判断题
     * @param requestData
     * @return
     */
    @Override
    public List<Subject> findJudgment(RequestData requestData) {
        List<Subject> list = judgmentDao.findJudgment(requestData.getMap());
        return list;
    }

    /**
     * 获取判断题的总数
     * @return
     */
    @Override
    public int getJudgmentCount() {
        return judgmentDao.getJudgmentCount();
    }

    /**
     * 根据类型和id查询判断题
     * @param sb_id
     * @return
     */
    @Override
    public List<Judgment> getJudgmentBySbAndId(int sb_id,int num) {
        return judgmentDao.getJudgmentBySbAndId(sb_id,num);
    }

    //根据id集合获取判断题
    @Override
    public List<Judgment> getJudgmentByIdsList(List<Integer> idsList) {
        return judgmentDao.getJudgmentByIdsList(idsList);
    }

    //获取判断题的答案
    @Override
    public JudgmentAnswer getAnswer(int id) {
        return judgmentAnswerDao.getAnswer(id);
    }
}
